﻿using AutoMapper;
using MediatR;
using MyMES.Domain.zyy;
using MyMES.Error;
using MyMES.Infrastructure.Interface;

namespace MyMES.Writer.API.Application.CommendHandlers.BOMguans
{
    public class UpdateBOMguanHandler : IRequestHandler<UpdateBOMguancommand, APIResult<BOMguan>>
    {
        private readonly IBaseRepository<BOMguan> baseRepository;
        private readonly IMapper mapper;

        public UpdateBOMguanHandler(IBaseRepository<BOMguan> baseRepository,IMapper mapper )
        {
            this.baseRepository = baseRepository;
            this.mapper = mapper;
        }

        public async Task<APIResult<BOMguan>> Handle(UpdateBOMguancommand request, CancellationToken cancellationToken)
        {
            APIResult<BOMguan> result= new APIResult<BOMguan> ();
            result.Code = APIEnum.修改成功;
            result.Msg = "修改成功";
            var model = mapper.Map<BOMguan>(request);
            string sql = "update BOMguan set BomNo=@BomNo,BomTheme=@BomTheme,BomDefault=@BomDefault,BomVersion=@BomVersion,BomType=@BomType,BomName=@BomName,DayNum=@DayNum,BomNote=@BomNote,WIds=@WIds,GIds=@GIds,Attachment=@Attachment,IsDeleted=@IsDeleted where BomId=@BomId";
            await baseRepository.Update(model, sql);
            return result;
        }
    }
}
